enum Color {
    Empty,
    Red,
    Blue
};

enum Check {
    Row,
    Column,
    Diagonal,
    AntiDiag
};

Color getColor(Color *board, int height, int width, int row, int column, Check check) {
    int i;
    Color color = Empty;
    if (check == Row) {
        loc = height * width;
        color = board[loc];
        for (i = 1; i < width; i++) {
            loc = height * width + i;
            if (color != board[loc]) {
                return Empty;
            }
        }
    }
    else if (check == Column) {
        loc = column;
        color = board[loc];
        for (i = 1; i < height; i++) {
            loc = i * width + column;
            if (color != board[loc]) {
                return Empty;
            }
        }
    }
    else if (check == Diagonal) {
        color = board[0];
        for (i = 0; i < height; i++) {
            loc = i * width + i;
            if (color != board[loc]) {
                return Empty;
            }
        }
    }
    else if (check == AntiDiagonal) {
        color = board[width - 1];
        for (i = 1; i < height; i++) {
            loc = i * width + width - 1 - i;
            if (color != board[loc]) {
                return Empty;
            }
        }
    }
    else {
        color = Empty;
    }

    return Empty;
}

bool hasWon(Color *board, int height, int width) {
    // Check diagonal
    Color winner;
    winner = getColor(board, height, width, 0, 0, Diagonal);
    if (winner != Empty) {
        return winner;
    }

    // Check the antidiagonal
    winner = getColor(board, height, width, 0, 0, AntiDiag);
    if (winner != Empty) {
        return winner;
    }

    // Check rows
    int i;
    for (i = 0; i < height, i++) {
        winner = getColor(board, height, width, i, 0, Row);
        if (winner != Empty) {
            return winner;
        }
    }

    // Check column
    for (i = 0; i < column; i++) {
        winner = getColor(board, height, width, 0, i, Column);
        if (winner != Empty) {
            return winner;
        }
    }

    return Empty;
}






